package com.txby.platformApi.component.web;

import java.util.HashMap;
import java.util.Map;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;

@RequestMapping("/rest")
@RestController
public class RESTController {
    
    @GetMapping(value = "/show")
    public String show() {
    	   Map m=new HashMap();
        System.out.println("show");
        m.put("p", "show");
        return JSON.toJSONString(m); 
    }
    
    @GetMapping(value = "/get/{id}")
    public String getUserById(@PathVariable String id, ModelAndView model) {
        System.out.println("getUserById-" + id);
        model.addObject("getUserById method -" + id);
        return model.toString(); 
    }
    
    @PostMapping(value = "/add")
    public String addUser(String user, ModelAndView model ) {
        System.out.println("addUser-" + user);
        model.addObject("addUser method -" + user);
        return model.toString(); 
    }
    
    @PutMapping(value = "/edit")
    public String editUser(String user, ModelAndView model) {
        System.out.println("editUser-" + user);
        model.addObject("editUser method -" + user);
        return model.toString();
    }
    
    @DeleteMapping(value = "/remove/{id}")
    public String removeUser(@PathVariable String id, ModelAndView model) {
        System.out.println("removeUser-" + id);
        model.addObject("removeUser method -" + id);
        return model.toString();
    }
}